﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PTTK_HTTT_06.BUS;
using System.Data;

namespace PTTK_HTTT_06.DAO
{
    class DON_VI_TINH_DB
    {
        public static DataTable LoadDonViTinh()
        {
            DataProvider _provider = new DataProvider();
            _provider.Connect();
            string sql = "select * from DON_VI_TINH";
            DataTable dt = _provider.ExcuteQueryDataTable(sql);
            _provider.Disconnect();
            return dt;
        }
        #region public static List<DON_VI_TINH> LayDanhSach()
        public static List<DON_VI_TINH> LayDanhSach(){
            DataProvider dataProvider = new DataProvider();
            string sqlStr = "select * from DON_VI_TINH";
            if (!dataProvider.IsConnect())
                dataProvider.Connect();
            DataTable dt = dataProvider.ExcuteQueryDataTable(sqlStr);
            dataProvider.Disconnect();

            if (dt != null && dt.Rows.Count <= 0)
                return null;

            List<DON_VI_TINH> donViTinhList = new List<DON_VI_TINH>();
            for (int i = 0, count = dt.Rows.Count; i < count; i++)
            {
                DON_VI_TINH donViTinh = new DON_VI_TINH();
                donViTinh.MaDonViTinh = int.Parse(dt.Rows[i]["MaDonViTinh"].ToString());
                donViTinh.TenDonViTinh = dt.Rows[i]["TenDonViTinh"].ToString();

                donViTinhList.Add(donViTinh);
            }

            return donViTinhList;
        }
        #endregion
    }
}
